/*global pi */
pi.mod.define('pi.scene.dbg', function (pi) {
	"use strict";

	var module = {},
		buff = pi.cbuffer.create(),
		vcalls = [
			["s3d_debug_get_ot_info", pi.vcall.TYPE_INT, [pi.vcall.TYPE_INT, pi.vcall.TYPE_INT]]
		];

	pi.vcall.makeVCall("s3d.dll", module, vcalls);

	// 创建场景八叉树的可视化模型
	module.showOctree = function (scene) {
		var i, objNum, cube, min = {}, max = {},
			num = vcalls.s3d_debug_get_ot_info(scene.handle, buff);
		
		for (i = 0; i < num; i++) {
			objNum = pi.cbuffer.readInt(buff);
			min = {
				x: pi.cbuffer.readFloat(buff),
				y: pi.cbuffer.readFloat(buff),
				z: pi.cbuffer.readFloat(buff)
			};
			max = {
				x: pi.cbuffer.readFloat(buff),
				y: pi.cbuffer.readFloat(buff),
				z: pi.cbuffer.readFloat(buff)
			};

			cube = scene.createCubeframe({r: 255, g: 255, b: 0, a: 255});
			cube.translucent = true;
			cube.setScale({
				x: max.x - min.x,
				y: max.y - min.y,
				z: max.z - min.z
			});
			cube.setPos({
				x: (max.x + min.x) / 2,
				y: (max.y + min.y) / 2,
				z: (max.z + min.z) / 2
			});
		} 
	};

	return module;
});